import { getUser, updateUser } from 'api/userApi'

export default {
  state: () => ({
    user: null
  }),
  getters: {
    user: state => state.user
  },
  mutations: {
    setUser(state, user) {
      state.user = user
    }
  },
  actions: {
    async getCurrentUser (context) {
      const userResponse = await getUser()
      context.commit('setUser', null)
      context.commit('setUser', userResponse)
    },
    async updateUser ({ commit }, params = {}) {
      const editResponse = await updateUser(params)
      commit('setUser', editResponse)
    }
  }
}
